package com.example.dinghao.widgettest_312dh;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tv;
    private EditText et;
    private Button btngettext,btnsetimage;
    private ImageView iv;
    private ImageButton ibtn;

    private RadioGroup rg;
    private RadioButton rbnan,rbnv;
    private CheckBox cblan,cbzu,cbyou;
    private Button btngetgender,btngetfun;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
    private void init() {
        tv = (TextView) findViewById(R.id.textView4);
        et = (EditText) findViewById(R.id.editText5);
        btngettext = (Button) findViewById(R.id.button4);
        btnsetimage = (Button) findViewById(R.id.button5);
        iv = (ImageView) findViewById(R.id.imageView);
        ibtn = (ImageButton) findViewById(R.id.imageButton);
        btngettext.setOnClickListener(this);
        btnsetimage.setOnClickListener(this);
        ibtn.setOnClickListener(this);

        rg = (RadioGroup) findViewById(R.id.radiogroup);
        rbnan = (RadioButton) findViewById(R.id.radioButton4);
        rbnv = (RadioButton) findViewById(R.id.radioButton3);
        cblan = (CheckBox) findViewById(R.id.checkBox4);
        cbzu = (CheckBox) findViewById(R.id.checkBox5);
        cbyou = (CheckBox) findViewById(R.id.checkBox3);
        btngetgender = (Button) findViewById(R.id.button);
        btngetfun = (Button) findViewById(R.id.button2);

        btngetgender.setOnClickListener(this);
        btngetfun.setOnClickListener(this);
    }
    public void onClick(View view){
        switch (view.getId()){
            case R.id.button4:
                String str=et.getText().toString();
                tv.setText(str);
                break;
            case R.id.button5:
                iv.setImageResource(R.drawable.f_angry);
                break;
            case R.id.imageButton:
                Intent intent=new  Intent(MainActivity.this,NewActivity.class);
                intent.putExtra("param1",et.getText().toString());
                intent.putExtra("param2",3);

                startActivity(intent);
                break;

            case R.id.button:
                if(rbnan.isChecked()) tv.setText("男");
                if(rbnv.isChecked()) tv.setText("女");
                break;

            case R.id.button2:
                String msg="";
                if(cblan.isChecked()) msg+="篮球+";
                if(cbzu.isChecked()) msg+="足球+";
                if(cbyou.isChecked()) msg+="游泳";
                tv.setText(msg);

        }

    }


}